package cn.gson.crm.model.service;

import cn.gson.crm.model.dao.BusinessDao;
import cn.gson.crm.model.dao.CheckDao;
import cn.gson.crm.model.mapper.BusinessMapper;
import cn.gson.crm.model.pojos.Business;
import cn.gson.crm.model.pojos.Check;
import cn.gson.crm.model.pojos.Employee;
import cn.gson.crm.model.pojos.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class EvectionService {
    @Autowired
    BusinessMapper businessMapper;
    @Autowired
    BusinessDao businessDao;
    @Autowired
    CheckDao checkDao;
    //查询所有出差申请
    public List<Business> selectbusiness(){ return  businessMapper.selectbusiness(); }
    //删除
    public int update1(String businessAppstate,int businessid){return businessMapper.update1(businessAppstate,businessid);}
    //条件查询
    public List<Business> selectbusiness2(String businessStartTime,String businessOverTime,String businessPlace, String businessName)
    {
        return  businessMapper.selectbusiness2(businessStartTime,businessOverTime,businessPlace,businessName);
    }
    //新增
    public void addBusiness(Business business, HttpSession session){
        User login = (User)session.getAttribute("login");
        int ygId=login.getyId();
        Business b = new Business();
        b.setBusinessState(business.getBusinessState());
        System.out.println("11"+business.getBusinessState());
        b.setBusinessAppstate(business.getBusinessAppstate());
        businessDao.save(business);
        //审核表新增
        Check check = new Check();
        check.setChecksqinName((long)ygId);
        check.setCheckType("出差申请");
        check.setChecktypeid((int)business.getBusinessId());
        check.setCheckDate(business.getBusinessStartTime());
        check.setCheckName(business.getEmployeeByYgId().getYgId());
        check.setCheckCondition("未审核");
        checkDao.save(check);
    }
    //查询员工
    public List<Employee> selectEmployee(){return businessMapper.selectEmployee();}
}
